﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace com.orange.examination
{
    public partial class WebForm11 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("../LoginAndRegister/Login.aspx");
            }
            else
            if (Page.IsPostBack)
            {
                //this.txtNewPwd.Attributes.Add("value", this.txtNewPwd.Text);
                //this.txtNewPwdA.Attributes.Add("value", this.txtNewPwdA.Text);
            }
        }

        protected void btnchange_Click(object sender, EventArgs e)
        {
            if (txtNewPwd.Text == "" || txtNewPwdA.Text == "" || txtOldPwd.Text == "")
            {
                Response.Write("<script type=text/javascript>alert('请将信息填写完整！')</script>");
                return;
            }
            else
            {
                if (BaseClass.CheckAdmin(Session["admin"].ToString(), txtOldPwd.Text.Trim()))
                {
                    if (txtNewPwd.Text.Trim() != txtNewPwdA.Text.Trim())
                    {
                        Response.Write("<script type=text/javascript>alert('两次密码不一致！')</script>");
                        return;
                    }
                    else
                    {
                        string strsql = "update tb_Admin set AdminPwd='" + txtNewPwdA.Text.Trim() + "' where AdminNum='" + Session["admin"].ToString() + "'";
                        BaseClass.OperateData(strsql);
                        //Response.Write("<script type=text/javascript>alert('密码修改成功！')</script>");
                        txtNewPwd.Text ="";
                        txtNewPwdA.Text ="";
                        txtOldPwd.Text ="";
                        Response.Write("<script type=text/javascript>alert('密码修改成功！')</script>");
                    }
                }
                else
                {
                    Response.Write("<script type=text/javascript>alert('旧密码输入错误！')</script>");
                    return;
                }
            }
        }

        protected void Cancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("/AdminManage");
        }

        protected void btnCle_Click(object sender, EventArgs e)
        {
            txtNewPwd.Text = "";
            txtNewPwdA.Text = "";
            txtOldPwd.Text = "";
        }
    }
}